home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 1997 #1
/
Amiga Plus CD - 1997 - No. 01.iso
/
pd
/
programmierung
/
installproged
/
sasc_support
/
sources
/
createsmakefile.c
next >
Wrap
C/C++ Source or Header
|
1996-03-11
|
5KB
|
258 lines
#include <proto/dos.h>
#include <proto/exec.h>
#include <exec/memory.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define MAXLEN 130
struct MyStruct {
struct AnchorPath anc;
char pad[MAXLEN];
} s;
void FreeList(struct List *list)
{
struct Node *n;
if (list)
while(!IsListEmpty(list))
{
n=RemHead(list);
FreeVec(n->ln_Name);
FreeVec(n);
}
}
void CreateList(struct List *list,char *pattern)
{
int err;
struct Node *node;
char *string;
NewList(list);
err=MatchFirst(pattern,(struct AnchorPath*)&s);
while(!err)
{
if (s.anc.ap_Info.fib_DirEntryType<0)
{
if (!(node=AllocVec(sizeof(struct Node),MEMF_CLEAR)))
{
MatchEnd((struct AnchorPath*)&s);
return;
}
if (!(string=AllocVec(strlen(&s.anc.ap_Buf[0])+1,MEMF_CLEAR)))
{
FreeVec(node);
MatchEnd((struct AnchorPath*)&s);
return;
}
strcpy(string,&s.anc.ap_Buf[0]);
node->ln_Name=string;
AddTail(list,node);
}
err=MatchNext((struct AnchorPath*)&s);
}
MatchEnd((struct AnchorPath*)&s);
}
void AddExt(char *nome,char *ext)
{
char *p=nome;
p+=strlen(p)-1;
while(p>=nome)
{
if (*p=='.')
{
strcpy(p+1,ext);
return;
}
p--;
}
strcat(nome,".");
strcat(nome,ext);
}
void main(int argc,char *argv[])
{
struct List C_List,
A_List,
H_List;
struct Node *node,
*node2;
int gst;
FILE *file;
BPTR dir;
char buffer[MAXLEN+1],
curdir[MAXLEN+1];
if ((argc!=4)&&(argc!=2))
{
printf("SYNTAX: %s <Executable> [<GST> <PreInclude>]\n",argv[0]);
exit(5);
}
if (argc==4) gst=TRUE;
else gst=FALSE;
s.anc.ap_Strlen=MAXLEN;
CreateList(&C_List,"#?.c");
CreateList(&A_List,"#?.a");
CreateList(&H_List,"#?.h");
if (gst)
{
for(node=C_List.lh_Head;node->ln_Succ;node=node->ln_Succ)
if (!stricmp(node->ln_Name,argv[3]))
break;
if (node->ln_Succ)
{
Remove(node);
FreeVec(node->ln_Name);
FreeVec(node);
}
}
if (!(dir=Lock("",ACCESS_READ)))
{
printf("Can't lock current dir!\n");
exit(5);
}
NameFromLock(dir,curdir,sizeof(curdir)-1);
UnLock(dir);
if (strlen(curdir)>0)
if ((curdir[strlen(curdir)-1]!=':')&&(curdir[strlen(curdir)-1]!='/'))
strcat(curdir,"/");
if (!(file=fopen("SMakefile","w")))
{
FreeList(&C_List);
FreeList(&A_List);
FreeList(&H_List);
exit(5);
}
fprintf(file,"\n");
fprintf(file,"AFLAGS\t= -Iinclude:\n");
fprintf(file,"\n");
fprintf(file,"CFLAGS\t=\n");
fprintf(file,"\n");
fprintf(file,"LFLAGS\t=\n");
fprintf(file,"\n");
fprintf(file,"OBJS\t= ");
for(node=C_List.lh_Head;node->ln_Succ;node=node->ln_Succ)
{
strcpy(buffer,node->ln_Name);
AddExt(buffer,"o");
fprintf(file,"%s ",buffer);
}
for(node=A_List.lh_Head;node->ln_Succ;node=node->ln_Succ)
{
strcpy(buffer,node->ln_Name);
AddExt(buffer,"o");
fprintf(file,"%s ",buffer);
}
fprintf(file,"\n");
fprintf(file,"\n");
fprintf(file,"LIBS\t= LIB:sc.lib LIB:amiga.lib\n");
fprintf(file,"\n");
if (gst) fprintf(file,"all: %s %s\n",argv[2],argv[1]);
else fprintf(file,"all: %s\n",argv[1]);
fprintf(file,"\n");
if (gst)
{
fprintf(file,"%s: PRJ:%s ",argv[2],argv[3]);
for(node=H_List.lh_Head;node->ln_Succ;node=node->ln_Succ)
fprintf(file,"PRJ:%s ",node->ln_Name);
fprintf(file,"\n");
fprintf(file,"\tSC:C/SC NOLINK ERRREXX OBJNAME T:Dummy.o MAKEGST=$@ PRJ:%s\n",argv[3]);
fprintf(file,"\tC:DELETE >NIL: T:Dummy.o\n");
fprintf(file,"\n");
}
fprintf(file,"%s: $(OBJS)\n",argv[1]);
fprintf(file,"\tSC:C/SLINK FROM LIB:c.o $(OBJS) TO $@ LIB $(LIBS) $(LFLAGS)\n");
fprintf(file,"\n");
for(node=C_List.lh_Head;node->ln_Succ;node=node->ln_Succ)
{
strcpy(buffer,node->ln_Name);
AddExt(buffer,"o");
fprintf(file,"%s: PRJ:%s ",buffer,node->ln_Name);
strcpy(buffer,curdir);
AddPart(buffer,node->ln_Name,sizeof(buffer)-1);
AddExt(buffer,"o");
for(node2=H_List.lh_Head;node2->ln_Succ;node2=node2->ln_Succ)
fprintf(file,"PRJ:%s ",node2->ln_Name);
fprintf(file,"\n");
fprintf(file,"\tSC:C/SC NOLINK ERRREXX $(CFLAGS) PRJ:%s OBJNAME %s",node->ln_Name,buffer);
if (gst) fprintf(file," GST=%s GSTIMM\n",argv[2]);
else fprintf(file,"\n");
fprintf(file,"\n");
}
for(node=A_List.lh_Head;node->ln_Succ;node=node->ln_Succ)
{
strcpy(buffer,node->ln_Name);
AddExt(buffer,"o");
fprintf(file,"%s: PRJ:%s ",buffer,node->ln_Name);
strcpy(buffer,curdir);
AddPart(buffer,node->ln_Name,sizeof(buffer)-1);
AddExt(buffer,"o");
for(node2=H_List.lh_Head;node2->ln_Succ;node2=node2->ln_Succ)
fprintf(file,"PRJ:%s ",node2->ln_Name);
fprintf(file,"\n");
fprintf(file,"\tSC:C/ASM $(AFLAGS) -o%s PRJ:%s\n",buffer,node->ln_Name);
fprintf(file,"\n");
}
fprintf(file,"\n");
fclose(file);
FreeList(&C_List);
FreeList(&A_List);
FreeList(&H_List);
exit(0);
}